package com.example.day14.annotation;

import com.example.day14.homework.Entity;

import java.lang.annotation.*;
import java.lang.reflect.Method;

@Target({ElementType.TYPE,ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface ExerCiseAnnotion {

    String value();
    int age();
}
@ExerCiseAnnotion(value = "xiuxian",age = 22)
class  MyAnnotation{

        @ExerCiseAnnotion(value = "jennie",age = 20)
        public   void test(){
            System.out.println("test.......annotation");
        }
}

class  TestMyanotion{
    public static void main(String[] args) {

        Class<?>  c=MyAnnotation.class;

        //查看有没有ExerCISEAnnotion注解
        if(c.isAnnotationPresent(ExerCiseAnnotion.class)){
            System.out.println("存在 exercise注解。。。。。。。。");
            ExerCiseAnnotion declaredAnnotation = c.getDeclaredAnnotation(ExerCiseAnnotion.class);
            System.out.println(declaredAnnotation.value());
            System.out.println(declaredAnnotation.age());
        }

        //获取当前类的方法中的数据
        try {
            Method m=c.getDeclaredMethod("test");
            if(c.isAnnotationPresent(ExerCiseAnnotion.class)){
                ExerCiseAnnotion declaredAnnotation = m.getDeclaredAnnotation(ExerCiseAnnotion.class);
                System.out.println(declaredAnnotation.value());
                System.out.println(declaredAnnotation.age());
            }
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }

    }
}
